package com.gxnzd.communityelderly.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxnzd.communityelderly.commom.R;
import com.gxnzd.communityelderly.entity.Community;
import com.gxnzd.communityelderly.service.CommunityService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: CommunityController
 * Package: com.gxnzd.communityelderly.controller
 * Description:
 *
 * @Author 胡海峰
 * @Create 2024/10/17 20:47
 * @Version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/community")
public class CommunityController {

    @Resource
    private CommunityService communityService;

    //列表
    @GetMapping("/list")
    public R<Page> list(Integer page,
                        Integer pageSize,
                        String communityName,
                        String districtsName,
                        String communityAddress,
                        Long communityId){
        return communityService.getList(page,pageSize,communityName,districtsName,communityAddress,communityId);
    }

    //模糊关键字查询
    @GetMapping("/keywords")
    public R<List<Community>> keywords(String communityName){
        return communityService.queryKeyWords(communityName);
    }

    //新增社区(未完成)
    @PostMapping("/add")
    public R add(@RequestBody Community community){
        return communityService.addCommunityInfo(community);
    }

    //修改社区（未完成）
    @PutMapping("/update")
    public R update(@RequestBody Community community){
        return communityService.updateCommunityInfo(community);
    }

    //删除社区(未完成)
    @DeleteMapping("/{communityId}")
    public R delete(@PathVariable Long communityId){
        return communityService.deleteCommunity(communityId);
    }

    //查询社区详细信息
    @GetMapping("/query/{communityId}")
    public R<Community> queryInfo(@PathVariable Long communityId){
        return communityService.getCommunityInfo(communityId);
    }

    //获取所有社区列表
    @GetMapping("/getAll")
    public R<List<Community>> getAll(){
        return  communityService.getAllList();
    }
}
